
package com.cxx.home.controller;

import com.cxx.common.ReadView;
import com.cxx.common.WriteView;
import com.cxx.home.dto.product.ProductDto;
import com.cxx.home.service.ProductService;
import com.cxx.home.vo.ProductQueryVo;
import com.fasterxml.jackson.annotation.JsonView;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/product")
@Tag(name = "商品清单")
public class ProductController {
    @Resource
    private ProductService productService;

    @Operation(summary = "新增商品清单")
    @PostMapping("")
    public Boolean addProduct(@RequestBody @JsonView(WriteView.class) @Validated ProductDto productDto) {
        return productService.addProduct(productDto);
    }

    @Operation(summary = "更新商品清单")
    @PutMapping("/{id}")
    public Boolean updateProduct(@PathVariable("id") long id,
                                 @RequestBody @JsonView(WriteView.class) @Validated ProductDto productDto) {
        return productService.updateProduct(id, productDto);
    }

    @Operation(summary = "删除商品清单")
    @DeleteMapping("/{id}")
    public Boolean deleteProduct(@PathVariable("id") long id) {
        return productService.deleteProduct(id);
    }

    @Operation(summary = "查询所有商品清单")
    @GetMapping("")
    public @JsonView(ReadView.class) List<ProductDto> queryProductList(ProductQueryVo queryVo) {
        return productService.queryProductList(queryVo);
    }

    @Operation(summary = "查询商品清单")
    @GetMapping("/{id}")
    public @JsonView(ReadView.class) ProductDto queryProduct(@PathVariable("id") long id) {
        return productService.queryProduct(id);
    }

    @Operation(summary = "查询商品类别")
    @GetMapping("/category")
    public List<String> queryProductCategory() {
        return productService.queryProductCategory();
    }
}
    